<template>
  <div class="content">
    <div class="content-main">
      <div class="btn-list-wrap">
        <div>
          <span>区域: </span>
          <el-select
            v-model="queryParams.areaCode"
            placeholder="请选择"
            clearable
            style="width: 120px"
          >
            <el-option
              v-for="item in areaOptions"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
        </div>
        <div>
          <span>产业领域: </span>
          <el-select
            v-model="queryParams.industryCode"
            placeholder="请选择"
            clearable
            style="width: 150px"
          >
            <el-option
              v-for="item in industryCodes"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
        </div>
        <div>
          <span>计量专业领域: </span>
          <el-select
            v-model="queryParams.professionCode"
            placeholder="请选择"
            clearable
            style="width: 100px"
          >
            <el-option
              v-for="item in professionCodes"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
        </div>
        <div>
          <span>年份: </span>
          <el-date-picker
            v-model="queryParams.vintage"
            type="year"
            format="YYYY"
            value-format="YYYY"
            placeholder="请选择"
          />
        </div>
        <div>
          <el-button type="primary" @click="getList" class="button-query">查询</el-button>
        </div>
      </div>
      <div class="list-wrap">
        <div class="list-info" v-for="(item, index) in infoList" :key="index">
          <div class="list-info-title">{{ item.caseName }}</div>
          <div class="list-info-content">
            <span class="list-info-info">{{ item.sector }}</span>
            <span class="list-info-btn" @click="jumpPage(item)">详情</span>
          </div>
        </div>
        <div class="pagination">
          <el-pagination
            layout="prev, pager, next"
            :total="queryParams.total"
            @current-change="currentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { cmsClassicCase } from '@/api'

const dictStore = useDictStore()

const industryCodes = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_INDUSTRY_CODE')
})
const areaOptions = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_AREA_CODE')
})
const professionCodes = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_PROFESSION_CODE')
})

const queryParams = reactive({
  industryCode: '',
  areaCode: '',
  professionCode: '',
  vintage: '',
  pageNum: 1,
  pageSize: 10,
  total: 0
})
const infoList = ref([])
const router = useRouter()
function jumpPage(item) {
  router.push({ path: 'typicalCaseDetails', query: { id: item.id } })
}
function currentChange(val) {
  queryParams.pageNum = val
  getList()
}
function getList() {
  cmsClassicCase({
    ...queryParams,
    pageNum: queryParams.pageNum,
    pageSize: queryParams.pageSize
  }).then(({ data }) => {
    infoList.value = data.list
    queryParams.total = data.total
  })
}
onMounted(() => {
  getList()
})
</script>
<style lang="scss" scoped>
.button-query {
  margin-left: 20px;
}
.content {
  background-color: #f6faff;
  padding-top: 20px;
}

.content-main {
  width: 1200px;
  min-height: 850px;
  margin: auto;

  .list-wrap {
    .list-info {
      margin-bottom: 20px;
      padding: 20px;
      background-color: #fff;

      .list-info-title {
        font-size: 18px;
        color: #333;
      }

      .list-info-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        height: 40px;
        font-size: 12px;
        color: #8992a9;

        .list-info-info {
        }

        .list-info-btn {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 76px;
          height: 30px;
          background: #1d5ede;
          font-size: 16px;
          color: #fff;
          cursor: pointer;
        }
      }

      .list-info-type {
        display: flex;
        align-items: center;
        margin-top: 10px;
        font-size: 14px;
        color: #8992a9;

        .list-info-type-title {
        }

        .list-info-type-value {
          margin: 0;
          margin-left: 10px;
          padding: 2px 6px;
          color: #1d5ede;
          background: #eff4ff;
        }
      }
    }
  }

  .btn-list-wrap {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    span {
      margin: 0 10px;
    }
  }

  .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
  }
}
</style>
